package net.lab1024.sa.admin.module.device.terminal;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import net.lab1024.sa.admin.constant.AdminSwaggerTagConst;
import net.lab1024.sa.admin.module.device.terminal.domain.DeviceTerminalQueryForm;
import net.lab1024.sa.admin.module.device.terminal.domain.DeviceTerminalVO;
import net.lab1024.sa.admin.module.system.login.domain.RequestEmployee;
import net.lab1024.sa.admin.util.AdminRequestUtil;
import net.lab1024.sa.base.common.domain.PageResult;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.module.support.operatelog.annotation.OperateLog;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = AdminSwaggerTagConst.Device.DEVICE_TERMINAL)
@OperateLog
@RestController
public class DeviceTerminalController {

    private final DeviceTerminalService deviceTerminalService;

    public DeviceTerminalController(DeviceTerminalService deviceTerminalService) {
        this.deviceTerminalService = deviceTerminalService;
    }

    @Operation(summary = "分页查询")
    @PostMapping("/device/terminal/page/query")
    @SaCheckPermission("device:terminal:query")
    public ResponseDTO<PageResult<DeviceTerminalVO>> queryByPage(@RequestBody DeviceTerminalQueryForm queryForm) {
        RequestEmployee requestUser = AdminRequestUtil.getRequestUser();
        PageResult<DeviceTerminalVO> pageResult = deviceTerminalService.queryByPage(queryForm, requestUser);
        return ResponseDTO.ok(pageResult);
    }

    @Operation(summary = "检查远程连接状态")
    @GetMapping("/device/terminal/checkRemoteLink")
    public ResponseDTO<Boolean> checkRemoteLink(String serialno) {
        Boolean remoteLinkFlag = deviceTerminalService.checkRemoteLink(serialno);
        return ResponseDTO.ok(remoteLinkFlag);
    }
}
